﻿using MyTestProject.NUnity.MVVM;
using MyTestProject.Validation;
using System;
using System.ComponentModel.DataAnnotations;
using System.Windows;

namespace MyTestProject.Core
{
    /// <summary>
    /// 配置实体
    /// </summary>
    public class ConfigModel : ObservableObject, IComparable<ConfigModel>
    {
        public ConfigModel() 
        {
            Id = Guid.NewGuid().ToString("N");
        }

        /// <summary>
        /// 唯一标识
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        private string _Name;
        [Required(ErrorMessage = "[名称]不能为空！")]
        [RequiredExtend("[名称]不能为空！")]
        [StringLength(100, ErrorMessage = "[名称]内容最大允许输入长度100！")]
        public string Name
    {
            get { return _Name; }
            set 
            {
                _Name = value;
                RaisePropertyChanged("Name");
            }
        }


        /// <summary>
        /// 初始值
        /// </summary>
        private string _InitialValue= "0.0";
        [Required(ErrorMessage = "[初始值]不能为空！")]
        [StringLength(25, ErrorMessage = "[初始值]内容最大允许输入长度25！")]
        [RegularExpression("^-?\\d+$|^(-?\\d+)(\\.\\d+)?$", ErrorMessage = "[初始值]只能输入数字！")]
        [NumberRule(-999999999, 999999999)]
        public string InitialValue
        {
            get { return _InitialValue; }
            set 
            { 
                _InitialValue = value;
                RaisePropertyChanged("InitialValue");
            }
        }


        /// <summary>
        /// 单位
        /// </summary>

        private string _Unit="/";
        public string Unit
        {
            get { return _Unit; }
            set 
            { 
                _Unit = value;
                RaisePropertyChanged("Unit");
            }
        }


        /// <summary>
        /// 值
        /// </summary>
        private string _Value= "0.0";
        [Required(ErrorMessage = "[值]不能为空！")]
        [StringLength(25, ErrorMessage = "[值]内容最大允许输入长度25！")]
        [RegularExpression("^-?\\d+$|^(-?\\d+)(\\.\\d+)?$", ErrorMessage = "[值]只能输入数字！")]
        [NumberRule(-999999999, 999999999)]
        public string Value
        {
            get { return _Value; }
            set 
            { 
                _Value = value;
                RaisePropertyChanged("Value");
            }
        }

        private bool _IsSelected;
        /// <summary>
        /// 是否选择
        /// </summary>
        public bool IsSelected
        {
            get { return _IsSelected; }
            set 
            {
                _IsSelected = value;
                RaisePropertyChanged("IsSelected");
            }
        }

        private Visibility _AddBtisibility=Visibility.Collapsed;
        /// <summary>
        /// 添加按钮是否显示
        /// </summary>
        public Visibility AddBtVisibility
        {
            get { return _AddBtisibility; }
            set 
            {
                _AddBtisibility = value;
                RaisePropertyChanged("AddBtVisibility");
            }
        }

        /// <summary>
        /// 是否是新添加
        /// </summary>
        public bool IsNewAdd { get; set; }

        public int CompareTo(ConfigModel other)
        {
          return this.Name.CompareTo(other.Name);
        }
    }
}
